<html>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="weui/css/weui.css"/>
<link rel="stylesheet" href="weui/css/weuix.css"/>
<script src="weui/js/zepto.min.js"></script>
<script src="weui/js/zepto.weui.js"></script>

<script src="EXPayPublic.js"></script>
<style>
    .pay{
        margin-left:2%;
        margin-bottom:5px;
        display:inline-block;
        width: 28%;
        height: 80px;
        border: 1px solid green;
        border-radius: 5%;
        flex-direction:row;
        text-align: center;

    }
    .paySpan{
        display:block;
        color: green;
        text-align:center;
        padding-top:10px;
        height:70px;
    }
</style>
<body style="margin: 20px">

    <div class="pay">
        <a href="javascript:void(0)" onclick="doPay(0.1)" style='text-decoration:none;'><span class="paySpan">0.1元<br>支付0.1元</span></a>
    </div>
    <div class="pay">
        <a href="javascript:void(0)" onclick="doPay(0.5)" style='text-decoration:none;'><span class="paySpan">0.5元<br>支付0.5元</span></a>
    </div>
    <div class="pay">
        <a href="javascript:void(0)" onclick="doPay(1)" style='text-decoration:none;' ><span class="paySpan">1元<br>支付1元</span></a>
    </div>
    <div class="pay">
        <a href="javascript:void(0)" onclick="doPay(2)" style='text-decoration:none;' ><span class="paySpan">2元<br>支付2元</span></a>
    </div>
    <div class="pay">
        <a href="javascript:void(0)" onclick="doPay(10)" style='text-decoration:none;' ><span class="paySpan">5元<br>支付5元</span></a>
    </div>
    <div class="pay">
        <a href="javascript:void(0)" onclick="doPay(10)" style='text-decoration:none;' ><span class="paySpan">10元<br>支付10元</span></a>
    </div>
    <div class="pay">
        <a href="javascript:void(0)" onclick="doPay(20)" style='text-decoration:none;' ><span class="paySpan">20元<br>支付20元</span></a>
    </div>
    <div class="pay">
        <a href="javascript:void(0)" onclick="doPay(30)" style='text-decoration:none;' ><span class="paySpan">30元<br>支付30元</span></a>
    </div>
    <div class="pay">
        <a href="javascript:void(0)" onclick="doPay(50)" style='text-decoration:none;' ><span class="paySpan">50元<br>支付50元</span></a>
    </div>
    
    
<script>
    function doPay(tradeAmount){
        var io=new Date().getTime();
        var params={
            orderId:""+io,
            orderName:"测试"+io,
            orderDesc:"测试"+io,
            orderDate:""+io,
            tradeAmount:tradeAmount,
            openId:"opbpBt31FPsJBzZ-5NppSaJpnke4",
            currentUrl:"http://192.168.2.112:8080/wx.html"
        };
        doEXPay(params);
      

    }
    function onBridgeReady(){
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
                "appId":getUrlParam("appId"),     //公众号名称，由商户传入
                "timeStamp":getUrlParam("timeStamp"),         //时间戳，自1970年以来的秒数
                "nonceStr":getUrlParam("nonceStr"), //随机串
                "package":getUrlParam("package"),
                "signType":"MD5",         //微信签名方式：
                "paySign":getUrlParam("paySign") //微信签名
            },
            function(res){
                if(res.err_msg == "get_brand_wcpay_request:ok" ){
                    
                     $.toast("支付成功");
                    window.location.href=getUrlParam("originalUrl");
                    setTimeout(function(){
                        /**
                         * 加入自己的业务逻辑
                         * */
                        window.location.href=getUrlParam("originalUrl");
                    },1000)
                } 
                if(res.err_msg == "get_brand_wcpay_request:cancel" ){
                    $.toast("您取消了支付", "cancel");
                    setTimeout(function(){
                        window.location.href=getUrlParam("originalUrl");
                    },1000)
                } 
        }); 
    }
    if("pay"===getUrlParam("mode")){
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        } 
    }
   
</script>
</body>
</html>
